//
//  CSYTextAttachment.swift
//  CSYEmoticonKeyboard__Test
//
//  Created by 姚彦兆 on 15/11/22.
//  Copyright © 2015年 姚彦兆. All rights reserved.
//

import UIKit

class CSYTextAttachment: NSTextAttachment {
    
    var chs : String?
    
    func getEmoticonAttachmentText(emoticonModel : CSYEmoticonModel , font : UIFont) -> NSAttributedString {
       
        //给文本附件添加图片
        image = UIImage(contentsOfFile: emoticonModel.pngPath ?? "")
        
        chs = emoticonModel.chs
        
        //设置控件Frame
        let emoticon_H : CGFloat = font.lineHeight
        
        let emoticonSize : CGRect = CGRectMake(0, -4, emoticon_H, emoticon_H)
        
        bounds = emoticonSize
        
        //将该附件设置为属性字符串
        let attribute : NSMutableAttributedString = NSMutableAttributedString(attributedString: NSAttributedString(attachment: self))
        
        attribute.addAttribute(NSFontAttributeName, value:font, range: NSRange(location: 0,length: 1))
        
        return attribute
        
    }
    

}
